package tr.gov.tubitak.bilgem.esya.certviewer.viwerasn;

//import com.sun.xml.internal.ws.util.StringUtils;
import sun.security.util.ObjectIdentifier;
import sun.security.x509.AccessDescription;
import sun.security.x509.AuthorityInfoAccessExtension;
import sun.security.x509.GeneralName;
import tr.gov.tubitak.bilgem.esya.certviewer.Bundle;

import java.util.HashMap;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 12/5/11
 * Time: 9:43 AM
 * To change this template use File | Settings | File Templates.
 */
public class EAuthorityInfoAccessExtesion implements ECertExtension {
    AuthorityInfoAccessExtension aiaExtension;
    @Override
    public String getName() {
        return Bundle.getString("EAuthorityInfoAccessExtesion.Name");
    }

    @Override
    public String getShortTitle() {
        List<AccessDescription> ads = aiaExtension.getAccessDescriptions();
        StringBuilder sb = new StringBuilder();
        for(int k=0;k<ads.size();k++)
        {
        AccessDescription ad = ads.get(k);
            ObjectIdentifier accessMethodObjID = ad.getAccessMethod();
            EAccessMethod eAccessMethod=new EAccessMethod(accessMethodObjID);
            String accessLocation = ad.getAccessLocation().toString();
            sb.append("["+(k+1)+"]");
            sb.append("\n  "+ Bundle.getString("EAuthorityInfoAccessExtesion.AccessMethod")+"="+eAccessMethod.toString());
            sb.append("\n     URL="+accessLocation.substring(accessLocation.indexOf(':') + 1) );
            sb.append("\n");
        }
        return sb.toString();
    }

    @Override
    public String getLongTitle() {
        return getShortTitle();
    }

    @Override
    public boolean isCritical() {
        return aiaExtension.isCritical();
    }

    @Override
    public void encode(byte[] data) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setAsnObject(Object asnObject) {
        if(asnObject instanceof AuthorityInfoAccessExtension)
        {
            aiaExtension = (AuthorityInfoAccessExtension) asnObject;
        }
        //To change body of implemented methods use File | Settings | File Templates.
    }
}
